package com.ibeetl.cms.util;

import com.alibaba.fastjson.JSONObject;
import com.ibeetl.vo.BaseDataVo;
import com.ibeetl.vo.RespBaseVo;
import org.springframework.util.StringUtils;

/**
 * 接口安全校验
 */
public class CheckSecurityUtil {

    private static final String AESKEY = "kieodlgnxxdqwerp";

    // 接口签名校验
    public static RespBaseVo preCheck(BaseDataVo vo){
        if(StringUtils.isEmpty(vo.getSignKey())){
            return RespBaseVo.fail("密文为空");
        }
//        if(StringUtils.isEmpty(vo.getOemId())){
//            return RespBaseVo.fail("平台编号为空");
//        }


        String jsonStr=AESUtils.decryptAES(vo.getSignKey(),AESKEY);
        if(jsonStr==null){
            return RespBaseVo.fail("签名解密失败");
        }
        JSONObject data=JSONObject.parseObject(jsonStr);
        long time=Long.parseLong(data.getString("time"));
        Long nowTime=System.currentTimeMillis()/1000;
        if(nowTime-time>2*60*60){  //2个小时
            return RespBaseVo.fail("请求超时");
        }
        return  RespBaseVo.success(data,"签名解密成功");
    }
}
